/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.xsjh.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.xsjh.entity.TestXsjh;
import com.thinkgem.jeesite.modules.xsjh.service.TestXsjhService;

/**
 * 销售机会Controller
 * @author wzhao1
 * @version 2017-06-12
 */
@Controller
@RequestMapping(value = "${adminPath}/xsjh/testXsjh")
public class TestXsjhController extends BaseController {

	@Autowired
	private TestXsjhService testXsjhService;
	
	@ModelAttribute
	public TestXsjh get(@RequestParam(required=false) String id) {
		TestXsjh entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = testXsjhService.get(id);
		}
		if (entity == null){
			entity = new TestXsjh();
		}
		return entity;
	}
	
	@RequiresPermissions("xsjh:testXsjh:view")
	@RequestMapping(value = {"list", ""})
	public String list(TestXsjh testXsjh, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TestXsjh> page = testXsjhService.findPage(new Page<TestXsjh>(request, response), testXsjh); 
		model.addAttribute("page", page);
		return "modules/xsjh/testXsjhList";
	}

	@RequiresPermissions("xsjh:testXsjh:view")
	@RequestMapping(value = "form")
	public String form(TestXsjh testXsjh, Model model) {
		model.addAttribute("testXsjh", testXsjh);
		return "modules/xsjh/testXsjhForm";
	}

	@RequiresPermissions("xsjh:testXsjh:edit")
	@RequestMapping(value = "save")
	public String save(TestXsjh testXsjh, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, testXsjh)){
			return form(testXsjh, model);
		}
		testXsjhService.save(testXsjh);
		addMessage(redirectAttributes, "保存销售机会成功");
		return "redirect:"+Global.getAdminPath()+"/xsjh/testXsjh/?repage";
	}
	
	@RequiresPermissions("xsjh:testXsjh:edit")
	@RequestMapping(value = "delete")
	public String delete(TestXsjh testXsjh, RedirectAttributes redirectAttributes) {
		testXsjhService.delete(testXsjh);
		addMessage(redirectAttributes, "删除销售机会成功");
		return "redirect:"+Global.getAdminPath()+"/xsjh/testXsjh/?repage";
	}

}